package com.example.multiactivitydemo

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText

class SecondActivity : AppCompatActivity() {

    private lateinit var etInput: EditText

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)

        etInput = findViewById(R.id.etInput)
        val btnConfirm: Button = findViewById(R.id.btnConfirm)
        val btnCancel: Button = findViewById(R.id.btnCancel)

        btnConfirm.setOnClickListener {
            val inputText = etInput.text.toString()
            val resultIntent = Intent().apply {
                putExtra("return_data", inputText)
            }
            setResult(Activity.RESULT_OK, resultIntent)
            finish()
        }

        btnCancel.setOnClickListener {
            setResult(Activity.RESULT_CANCELED)
            finish()
        }
    }
}